package com.songlanyun.modules.order.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.songlanyun.common.utils.PageUtils;
import com.songlanyun.common.validator.ValidatorUtils;
import com.songlanyun.modules.order.dao.OrderReceiptDao;
import com.songlanyun.modules.order.entity.OrderReceipt;
import com.songlanyun.modules.order.service.OrderReceiptService;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 订单收件人信息服务
 */
@Service("orderReceiptService")
public class OrderReceiptServiceImpl extends ServiceImpl<OrderReceiptDao, OrderReceipt> implements OrderReceiptService {


    /**
     * 创建收件人信息
     *
     * @param entity
     * @return
     */
    @Override
    public OrderReceipt create(OrderReceipt entity) {
        ValidatorUtils.validateEntity(entity);
        this.baseMapper.insert(entity);
        return entity;
    }

    /**
     * 修改收货人信息
     *
     * @param entity
     * @return
     */
    @Override
    public OrderReceipt modify(OrderReceipt entity) {
        ValidatorUtils.validateEntity(entity);
        this.baseMapper.updateById(entity);
        return entity;
    }

    @Override
    public void remove(Long id) {

    }

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        return null;
    }

    @Override
    public OrderReceipt loadOrderReceiptBy(Long orderId) {
        return this.baseMapper.selectOne(new LambdaQueryWrapper<OrderReceipt>()
                .eq(OrderReceipt::getOrderId, orderId)
                .last("limit 1"));
    }
}
